<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个性化刷题平台 - 龙制作</title>
    <!-- Tailwind CSS v3 -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- 统一的 Tailwind 配置 -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#8B5CF6', // 主紫色
                        secondary: '#6D28D9', // 深紫色
                        accent: '#A78BFA', // 浅紫色
                        neutral: '#F3F4F6', // 背景色
                        'neutral-dark': '#1F2937', // 深色文本
                    },
                    fontFamily: {
                        sans: ['Inter', 'system-ui', 'sans-serif'],
                    },
                    animation: {
                        'fade-in': 'fadeIn 0.3s ease-in-out',
                        'slide-in': 'slideIn 0.3s ease-in-out',
                        'bounce-light': 'bounceLight 0.5s ease-in-out',
                    },
                    keyframes: {
                        fadeIn: {
                            '0%': { opacity: '0' },
                            '100%': { opacity: '1' },
                        },
                        slideIn: {
                            '0%': { transform: 'translateY(10px)', opacity: '0' },
                            '100%': { transform: 'translateY(0)', opacity: '1' },
                        },
                        bounceLight: {
                            '0%, 100%': { transform: 'scale(1)' },
                            '50%': { transform: 'scale(1.03)' },
                        },
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .glass-effect {
                @apply bg-white bg-opacity-80 backdrop-blur-md;
            }
            .card-shadow {
                @apply shadow-lg hover:shadow-xl transition-shadow duration-300;
            }
            .btn-primary {
                @apply bg-primary hover:bg-secondary text-white font-medium py-2 px-4 rounded-lg transition-colors duration-300 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-opacity-50;
            }
            .btn-secondary {
                @apply bg-white hover:bg-gray-100 text-primary border border-primary font-medium py-2 px-4 rounded-lg transition-colors duration-300 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-opacity-50;
            }
            .btn-danger {
                @apply bg-red-500 hover:bg-red-600 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-300 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-opacity-50;
            }
            .input-field {
                @apply w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent;
            }
            .nav-item {
                @apply flex items-center gap-2 px-3 py-2 rounded-lg transition-colors duration-300;
            }
            .nav-item.active {
                @apply bg-primary text-white;
            }
            .nav-item:not(.active) {
                @apply text-gray-600 hover:bg-gray-100;
            }
            .question-card {
                @apply bg-white rounded-xl p-5 card-shadow mb-5 animate-fade-in;
            }
            /* 选项卡片样式 - 优化大小和交互 */
            .option-item {
                @apply flex items-center gap-3 p-3 border-2 border-gray-200 rounded-lg cursor-pointer transition-all duration-300 text-base mb-2;
            }
            .option-item:hover {
                @apply border-primary bg-primary/5 scale-[1.01]; /* 鼠标悬停明显提示 */
            }
            .option-marker {
                @apply w-6 h-6 rounded-full bg-gray-200 flex items-center justify-center text-gray-700 font-bold text-sm min-w-[24px];
            }
            .option-item.selected .option-marker {
                @apply bg-primary text-white;
            }
            .option-item.correct .option-marker {
                @apply bg-green-500 text-white;
            }
            .option-item.incorrect .option-marker {
                @apply bg-red-500 text-white;
            }
            .option-item.selected {
                @apply border-primary bg-primary/10 font-medium ring-2 ring-primary/30;
            }
            .option-item.correct {
                @apply border-green-500 bg-green-500/10 font-medium ring-2 ring-green-500/30;
            }
            .option-item.incorrect {
                @apply border-red-500 bg-red-500/10 font-medium ring-2 ring-red-500/30;
            }
            .badge {
                @apply px-2 py-1 text-xs font-medium rounded-full;
            }
            .badge-primary {
                @apply bg-primary/20 text-primary;
            }
            .badge-success {
                @apply bg-green-500/20 text-green-500;
            }
            .badge-error {
                @apply bg-red-500/20 text-red-500;
            }
            .badge-warning {
                @apply bg-yellow-500/20 text-yellow-500;
            }
            /* 答案提示样式 */
            .answer-feedback {
                @apply py-2 px-3 rounded-lg text-center text-lg font-bold mt-3 mb-2 animate-bounce-light;
            }
            .feedback-correct {
                @apply bg-green-100 text-green-700 border border-green-200;
            }
            .feedback-incorrect {
                @apply bg-red-100 text-red-700 border border-red-200;
            }
            /* 题型标签样式 */
            .question-type-tag {
                @apply inline-block px-3 py-1 rounded-full text-sm font-medium mb-3;
            }
            .type-single {
                @apply bg-blue-100 text-blue-700;
            }
            .type-multiple {
                @apply bg-green-100 text-green-700;
            }
            .type-boolean {
                @apply bg-yellow-100 text-yellow-700;
            }
            /* 正确答案提示 */
            .correct-answer-hint {
                @apply mt-2 p-3 bg-blue-50 border border-blue-100 rounded-lg text-sm;
            }
            /* 提交提示 */
            .submit-prompt {
                @apply mt-3 p-3 bg-primary/10 border border-primary/30 rounded-lg flex items-center justify-between;
            }
            /* 关于页面样式 */
            .poem-container {
                @apply bg-white rounded-xl p-6 card-shadow text-center max-w-2xl mx-auto;
            }
            .poem-title {
                @apply text-2xl font-bold mb-2 text-primary;
            }
            .poem-author {
                @apply text-gray-600 mb-6 italic;
            }
            .poem-content {
                @apply text-gray-800 leading-relaxed whitespace-pre-line;
            }
        }
    </style>
</head>
<body class="bg-neutral min-h-screen font-sans text-neutral-dark">
    <div class="container mx-auto px-3 py-5 max-w-7xl">
        <!-- 头部 -->
        <header class="mb-5">
            <div class="flex justify-between items-center">
                <div class="flex items-center gap-2">
                    <div class="w-9 h-9 rounded-full bg-primary flex items-center justify-center text-white">
                        <i class="fa fa-book"></i>
                    </div>
                    <h1 class="text-xl font-bold text-primary">个性化刷题平台</h1>
                </div>
                <div class="text-xs text-gray-500 hidden sm:block">
                    龙哥制作，祝你刷题愉快
                </div>
            </div>
        </header>

        <!-- 主内容区 -->
        <div class="flex flex-col lg:flex-row gap-4">
            <!-- 左侧导航 - 移动端可折叠 -->
            <aside class="w-full lg:w-56 glass-effect rounded-xl p-3 h-fit mb-4 lg:mb-0">
                <nav>
                    <ul class="space-y-1">
                        <li>
                            <a href="#" class="nav-item active" data-section="dashboard">
                                <i class="fa fa-tachometer"></i>
                                <span>数据概览</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="nav-item" data-section="question-bank">
                                <i class="fa fa-list-alt"></i>
                                <span>题库管理</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="nav-item" data-section="start-quiz">
                                <i class="fa fa-play-circle"></i>
                                <span>开始测试</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="nav-item" data-section="wrong-questions">
                                <i class="fa fa-exclamation-circle"></i>
                                <span>错题记录</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="nav-item" data-section="about">
                                <i class="fa fa-info-circle"></i>
                                <span>关于</span>
                            </a>
                        </li>
                    </ul>
                </nav>
                
                <div class="mt-5 pt-4 border-t border-gray-200">
                    <h3 class="text-xs font-medium text-gray-500 mb-3">题库操作</h3>
                    <div class="space-y-2">
                        <button id="export-btn" class="btn-secondary w-full flex items-center justify-center gap-2">
                            <i class="fa fa-download"></i>
                            <span>导出题库</span>
                        </button>
                        <div class="relative">
                            <label for="import-file" class="btn-secondary w-full flex items-center justify-center gap-2 cursor-pointer">
                                <i class="fa fa-upload"></i>
                                <span>导入题库</span>
                            </label>
                            <input type="file" id="import-file" accept=".txt" class="absolute inset-0 opacity-0 cursor-pointer">
                        </div>
                        <button id="clear-all-btn" class="btn-danger w-full flex items-center justify-center gap-2">
                            <i class="fa fa-trash"></i>
                            <span>清空题库</span>
                        </button>
                    </div>
                </div>
            </aside>

            <!-- 右侧内容区 -->
            <main class="flex-1 glass-effect rounded-xl p-4">
                <!-- 数据概览 -->
                <section id="dashboard-section" class="section-content">
                    <h2 class="text-lg font-bold mb-4 flex items-center gap-2">
                        <i class="fa fa-tachometer text-primary"></i>
                        数据概览
                    </h2>
                    
                    <div class="grid grid-cols-2 md:grid-cols-4 gap-3 mb-5">
                        <div class="bg-white rounded-xl p-4 card-shadow">
                            <div class="flex items-center justify-between mb-2">
                                <h3 class="text-gray-500 text-sm">总题数</h3>
                                <div class="w-8 h-8 rounded-full bg-primary bg-opacity-10 flex items-center justify-center text-primary">
                                    <i class="fa fa-list-alt"></i>
                                </div>
                            </div>
                            <p class="text-2xl font-bold" id="total-questions">0</p>
                        </div>
                        
                        <div class="bg-white rounded-xl p-4 card-shadow">
                            <div class="flex items-center justify-between mb-2">
                                <h3 class="text-gray-500 text-sm">单选题</h3>
                                <div class="w-8 h-8 rounded-full bg-blue-100 flex items-center justify-center text-blue-500">
                                    <i class="fa fa-dot-circle-o"></i>
                                </div>
                            </div>
                            <p class="text-2xl font-bold" id="single-choice">0</p>
                        </div>
                        
                        <div class="bg-white rounded-xl p-4 card-shadow">
                            <div class="flex items-center justify-between mb-2">
                                <h3 class="text-gray-500 text-sm">多选题</h3>
                                <div class="w-8 h-8 rounded-full bg-green-100 flex items-center justify-center text-green-500">
                                    <i class="fa fa-check-square-o"></i>
                                </div>
                            </div>
                            <p class="text-2xl font-bold" id="multiple-choice">0</p>
                        </div>
                        
                        <div class="bg-white rounded-xl p-4 card-shadow">
                            <div class="flex items-center justify-between mb-2">
                                <h3 class="text-gray-500 text-sm">判断题</h3>
                                <div class="w-8 h-8 rounded-full bg-yellow-100 flex items-center justify-center text-yellow-500">
                                    <i class="fa fa-question-circle"></i>
                                </div>
                            </div>
                            <p class="text-2xl font-bold" id="true-false">0</p>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl p-4 card-shadow">
                        <h3 class="text-base font-semibold mb-3">最近测试记录</h3>
                        <div id="recent-tests" class="space-y-3">
                            <p class="text-gray-500 text-center py-3">暂无测试记录</p>
                        </div>
                    </div>
                </section>

                <!-- 题库管理 -->
                <section id="question-bank-section" class="section-content hidden">
                    <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 mb-4">
                        <h2 class="text-lg font-bold flex items-center gap-2">
                            <i class="fa fa-list-alt text-primary"></i>
                            题库管理
                        </h2>
                        <div class="flex flex-col sm:flex-row gap-2 w-full sm:w-auto">
                            <div class="relative w-full sm:w-48">
                                <input type="text" id="search-questions" placeholder="搜索题目..." class="input-field pl-8">
                                <i class="fa fa-search absolute left-2.5 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                            </div>
                            <select id="filter-question-type" class="input-field w-full sm:w-36">
                                <option value="all">全部题型</option>
                                <option value="single">单选题</option>
                                <option value="multiple">多选题</option>
                                <option value="boolean">判断题</option>
                            </select>
                        </div>
                    </div>
                    
                    <div id="questions-list" class="space-y-3">
                        <p class="text-gray-500 text-center py-6">题库为空，请导入题目</p>
                    </div>
                </section>

                <!-- 开始测试 -->
                <section id="start-quiz-section" class="section-content hidden">
                    <h2 class="text-lg font-bold mb-4 flex items-center gap-2">
                        <i class="fa fa-play-circle text-primary"></i>
                        开始测试
                    </h2>
                    
                    <div id="quiz-settings" class="bg-white rounded-xl p-4 card-shadow mb-4">
                        <h3 class="text-base font-semibold mb-3">测试设置</h3>
                        <div class="grid grid-cols-1 gap-4">
                            <div>
                                <label for="quiz-question-type" class="block text-sm font-medium text-gray-700 mb-1">题目类型</label>
                                <select id="quiz-question-type" class="input-field">
                                    <option value="all">全部题型</option>
                                    <option value="single">单选题</option>
                                    <option value="multiple">多选题</option>
                                    <option value="boolean">判断题</option>
                                </select>
                            </div>
                            <div>
                                <label for="quiz-question-count" class="block text-sm font-medium text-gray-700 mb-1">题目数量</label>
                                <input type="number" id="quiz-question-count" min="1" max="100" value="10" class="input-field">
                            </div>
                        </div>
                        <div class="mt-4 flex justify-end">
                            <button id="start-quiz-btn" class="btn-primary">开始测试</button>
                        </div>
                    </div>
                    
                    <div id="quiz-container" class="hidden">
                        <div class="flex justify-between items-center mb-3">
                            <div class="flex items-center gap-2">
                                <span class="badge badge-primary" id="current-question-number">1/10</span>
                            </div>
                            <div class="flex gap-2">
                                <span class="text-sm text-gray-500">得分: <span id="current-score">0</span></span>
                                <button id="end-quiz-btn" class="btn-danger text-xs py-1">
                                    <i class="fa fa-stop mr-1"></i>结束测试
                                </button>
                            </div>
                        </div>
                        
                        <div id="question-card" class="question-card">
                            <!-- 题型标签 -->
                            <div id="question-type-tag" class="question-type-tag"></div>
                            
                            <h3 id="quiz-question-text" class="text-base font-medium mb-4">题目加载中...</h3>
                            
                            <!-- 提交提示 - 仅多选题显示 -->
                            <div id="submit-prompt-container" class="submit-prompt hidden">
                                <span class="text-sm text-primary">此处提交按钮仅对多选题型有效</span>
                                <button id="submit-btn" class="btn-primary text-sm py-1">提交</button>
                            </div>
                            
                            <!-- 答案提示区域 -->
                            <div id="answer-feedback" class="hidden"></div>
                            
                            <!-- 正确答案提示 -->
                            <div id="correct-answer-hint" class="correct-answer-hint hidden"></div>
                            
                            <div id="quiz-options" class="space-y-3">
                                <!-- 选项将通过JavaScript动态生成 -->
                            </div>
                        </div>
                        
                        <div class="flex justify-between mt-4">
                            <button id="prev-question-btn" class="btn-secondary" disabled>上一题</button>
                            <button id="next-question-btn" class="btn-primary">下一题</button>
                        </div>
                    </div>
                    
                    <div id="quiz-result" class="hidden">
                        <div class="bg-white rounded-xl p-5 card-shadow text-center">
                            <div class="w-16 h-16 rounded-full bg-primary bg-opacity-10 flex items-center justify-center text-primary mx-auto mb-3">
                                <i class="fa fa-check-circle text-3xl"></i>
                            </div>
                            <h3 class="text-lg font-bold mb-1">测试完成!</h3>
                            <p class="text-gray-600 mb-4">你的得分: <span id="final-score" class="text-xl font-bold text-primary">0</span> / <span id="total-quiz-questions">0</span></p>
                            
                            <div class="grid grid-cols-3 gap-3 mb-4">
                                <div class="bg-gray-50 rounded-lg p-3">
                                    <p class="text-gray-500 text-xs">总题数</p>
                                    <p class="text-lg font-bold" id="result-total">0</p>
                                </div>
                                <div class="bg-green-50 rounded-lg p-3">
                                    <p class="text-green-500 text-xs">正确</p>
                                    <p class="text-lg font-bold" id="result-correct">0</p>
                                </div>
                                <div class="bg-red-50 rounded-lg p-3">
                                    <p class="text-red-500 text-xs">错误</p>
                                    <p class="text-lg font-bold" id="result-incorrect">0</p>
                                </div>
                            </div>
                            
                            <div class="flex justify-center gap-2">
                                <button id="restart-quiz-btn" class="btn-primary">重新测试</button>
                            </div>
                        </div>
                    </div>
                </section>

                <!-- 错题记录 -->
                <section id="wrong-questions-section" class="section-content hidden">
                    <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 mb-4">
                        <h2 class="text-lg font-bold flex items-center gap-2">
                            <i class="fa fa-exclamation-circle text-primary"></i>
                            错题记录
                        </h2>
                        <button id="start-wrong-quiz-btn" class="btn-primary w-full sm:w-auto">
                            <i class="fa fa-play-circle mr-1"></i>
                            错题测试
                        </button>
                    </div>
                    
                    <div id="wrong-questions-list" class="space-y-3">
                        <p class="text-gray-500 text-center py-6">暂无错题记录</p>
                    </div>
                </section>

                <!-- 关于 -->
                <section id="about-section" class="section-content hidden">
                    <h2 class="text-lg font-bold mb-4 flex items-center gap-2">
                        <i class="fa fa-info-circle text-primary"></i>
                        关于
                    </h2>
                    
                    <div class="poem-container">
                        <h3 class="poem-title">将进酒</h3>
                        <p class="poem-author">唐朝　李白</p>
                        <div class="poem-content">
君不见黄河之水天上来，奔流到海不复回。

君不见高堂明镜悲白发，朝如青丝暮成雪。

人生得意须尽欢，莫使金樽空对月。

天生我材必有用，千金散尽还复来。

烹羊宰牛且为乐，会须一饮三百杯。

岑夫子，丹丘生，将进酒，杯莫停。

与君歌一曲，请君为我倾耳听。

钟鼓馔玉不足贵，但愿长醉不复醒。

古来圣贤皆寂寞，惟有饮者留其名。

陈王昔时宴平乐，斗酒十千恣欢谑。


主人何为言少钱，径须沽取对君酌。

五花马，千金裘，呼儿将出换美酒，

与尔同销万古愁。
                        </div>
                    </div>
                </section>

                <!-- 编辑题目模态框 -->
                <div id="edit-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
                    <div class="bg-white rounded-xl p-4 w-full max-w-md max-h-[90vh] overflow-y-auto mx-3">
                        <div class="flex justify-between items-center mb-4">
                            <h3 class="text-base font-bold">编辑题目</h3>
                            <button id="close-edit-modal" class="text-gray-500 hover:text-gray-700">
                                <i class="fa fa-times text-lg"></i>
                            </button>
                        </div>
                        
                        <form id="edit-question-form">
                            <input type="hidden" id="edit-question-id">
                            
                            <div class="mb-4">
                                <label for="edit-question-type" class="block text-sm font-medium text-gray-700 mb-1">题目类型</label>
                                <select id="edit-question-type" class="input-field">
                                    <option value="single">单选题</option>
                                    <option value="multiple">多选题</option>
                                    <option value="boolean">判断题</option>
                                </select>
                            </div>
                            
                            <div class="mb-4">
                                <label for="edit-question-text" class="block text-sm font-medium text-gray-700 mb-1">题目内容</label>
                                <textarea id="edit-question-text" rows="2" placeholder="请输入题目内容..." class="input-field"></textarea>
                            </div>
                            
                            <div id="edit-options-container" class="mb-4">
                                <div class="flex justify-between items-center mb-1">
                                    <label class="block text-sm font-medium text-gray-700">选项</label>
                                    <button type="button" id="edit-add-option-btn" class="text-primary hover:text-secondary text-sm flex items-center gap-1">
                                        <i class="fa fa-plus-circle"></i> 添加选项
                                    </button>
                                </div>
                                <div class="edit-options-list space-y-3">
                                    <div class="flex items-center gap-2">
                                        <div class="w-7 h-7 rounded-full bg-primary flex items-center justify-center text-white font-medium">A</div>
                                        <input type="text" class="edit-option-input input-field" placeholder="选项A">
                                        <button type="button" class="edit-remove-option-btn text-gray-400 hover:text-red-500 hidden">
                                            <i class="fa fa-times"></i>
                                        </button>
                                    </div>
                                    <div class="flex items-center gap-2">
                                        <div class="w-7 h-7 rounded-full bg-primary flex items-center justify-center text-white font-medium">B</div>
                                        <input type="text" class="edit-option-input input-field" placeholder="选项B">
                                        <button type="button" class="edit-remove-option-btn text-gray-400 hover:text-red-500 hidden">
                                            <i class="fa fa-times"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="mb-4">
                                <label for="edit-answer-selection" class="block text-sm font-medium text-gray-700 mb-1">正确答案</label>
                                <div id="edit-answer-selection" class="flex flex-wrap gap-2 p-2 border border-gray-200 rounded-lg">
                                    <!-- 动态生成答案选择框 -->
                                </div>
                            </div>
                            
                            <div id="edit-boolean-options" class="mb-4 hidden">
                                <div class="flex gap-3">
                                    <div class="flex-1">
                                        <label class="option-item">
                                            <div class="option-marker">A</div>
                                            <span>正确</span>
                                            <input type="radio" name="edit-boolean-answer" value="true" class="hidden">
                                        </label>
                                    </div>
                                    <div class="flex-1">
                                        <label class="option-item">
                                            <div class="option-marker">B</div>
                                            <span>错误</span>
                                            <input type="radio" name="edit-boolean-answer" value="false" class="hidden">
                                        </label>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="flex justify-end gap-2">
                                <button type="button" id="cancel-edit-question" class="btn-secondary">取消</button>
                                <button type="submit" class="btn-primary">保存修改</button>
                            </div>
                        </form>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <script>
        // 数据存储模块
        const DataStore = {
            // 初始化数据
            init() {
                if (!localStorage.getItem('questionBank')) {
                    localStorage.setItem('questionBank', JSON.stringify([]));
                }
                
                if (!localStorage.getItem('wrongQuestions')) {
                    localStorage.setItem('wrongQuestions', JSON.stringify([]));
                }
                
                if (!localStorage.getItem('testRecords')) {
                    localStorage.setItem('testRecords', JSON.stringify([]));
                }
                
                if (!localStorage.getItem('currentQuiz')) {
                    localStorage.setItem('currentQuiz', JSON.stringify(null));
                }
            },
            
            // 获取题库
            getQuestionBank() {
                return JSON.parse(localStorage.getItem('questionBank') || '[]');
            },
            
            // 保存题库
            saveQuestionBank(questions) {
                localStorage.setItem('questionBank', JSON.stringify(questions));
                this.updateDashboard();
                this.updateQuestionBankList();
                this.updateWrongQuestionsList();
            },
            
            // 添加题目
            addQuestion(question) {
                const questions = this.getQuestionBank();
                question.id = Date.now().toString(); // 使用时间戳作为唯一ID
                questions.push(question);
                this.saveQuestionBank(questions);
                return question;
            },
            
            // 更新题目
            updateQuestion(updatedQuestion) {
                const questions = this.getQuestionBank();
                const index = questions.findIndex(q => q.id === updatedQuestion.id);
                if (index !== -1) {
                    questions[index] = updatedQuestion;
                    this.saveQuestionBank(questions);
                    return true;
                }
                return false;
            },
            
            // 删除题目
            deleteQuestion(id) {
                const questions = this.getQuestionBank();
                const newQuestions = questions.filter(q => q.id !== id);
                this.saveQuestionBank(newQuestions);
                
                // 同时从错题记录中删除
                const wrongQuestions = this.getWrongQuestions();
                const newWrongQuestions = wrongQuestions.filter(q => q.id !== id);
                this.saveWrongQuestions(newWrongQuestions);
                
                return true;
            },
            
            // 获取错题记录
            getWrongQuestions() {
                return JSON.parse(localStorage.getItem('wrongQuestions') || '[]');
            },
            
            // 保存错题记录
            saveWrongQuestions(questions) {
                localStorage.setItem('wrongQuestions', JSON.stringify(questions));
                this.updateWrongQuestionsList();
            },
            
            // 添加错题
            addWrongQuestion(question) {
                const wrongQuestions = this.getWrongQuestions();
                const existingIndex = wrongQuestions.findIndex(q => q.id === question.id);
                
                if (existingIndex === -1) {
                    wrongQuestions.push({...question, wrongCount: 1});
                    this.saveWrongQuestions(wrongQuestions);
                } else {
                    // 如果已经存在，更新错误次数
                    wrongQuestions[existingIndex].wrongCount++;
                    this.saveWrongQuestions(wrongQuestions);
                }
            },
            
            // 移除错题
            removeWrongQuestion(id) {
                const wrongQuestions = this.getWrongQuestions();
                const newWrongQuestions = wrongQuestions.filter(q => q.id !== id);
                this.saveWrongQuestions(newWrongQuestions);
            },
            
            // 获取测试记录
            getTestRecords() {
                return JSON.parse(localStorage.getItem('testRecords') || '[]');
            },
            
            // 添加测试记录
            addTestRecord(record) {
                const records = this.getTestRecords();
                record.id = Date.now().toString();
                record.date = new Date().toLocaleString();
                records.unshift(record); // 添加到开头
                localStorage.setItem('testRecords', JSON.stringify(records));
                this.updateDashboard();
            },
            
            // 获取当前测试
            getCurrentQuiz() {
                return JSON.parse(localStorage.getItem('currentQuiz') || 'null');
            },
            
            // 保存当前测试
            saveCurrentQuiz(quiz) {
                localStorage.setItem('currentQuiz', JSON.stringify(quiz));
            },
            
            // 清除当前测试
            clearCurrentQuiz() {
                this.saveCurrentQuiz(null);
            },
            
            // 导出题库
            exportQuestionBank() {
                const questions = this.getQuestionBank();
                let text = '';
                
                questions.forEach((q, index) => {
                    text += `#${index + 1} ${this.getQuestionTypeText(q.type)}\n`;
                    text += `${q.text}\n`;
                    
                    if (q.type !== 'boolean') {
                        q.options.forEach((option, i) => {
                            const optionLetter = String.fromCharCode(65 + i);
                            text += `${optionLetter}.${option}\n`;
                        });
                    } else {
                        text += `A.正确\nB.错误\n`;
                    }
                    
                    text += `答案:${this.formatAnswer(q)}\n\n`;
                });
                
                this.downloadTextFile(text, '题库导出.txt');
            },
            
            // 导入题库
            importQuestionBank(text) {
                try {
                    const lines = text.split('\n').map(line => line.trim()).filter(line => line);
                    const questions = [];
                    let currentQuestion = null;
                    
                    lines.forEach(line => {
                        // 题目开始标记：#数字 题型
                        const questionStart = line.match(/^#(\d+)\s*(单选题|多选题|判断题)$/);
                        if (questionStart) {
                            if (currentQuestion) {
                                questions.push(currentQuestion);
                            }
                            
                            const typeMap = {
                                '单选题': 'single',
                                '多选题': 'multiple',
                                '判断题': 'boolean'
                            };
                            
                            currentQuestion = {
                                id: Date.now().toString() + Math.floor(Math.random() * 1000),
                                type: typeMap[questionStart[2]] || 'single',
                                text: '',
                                options: [],
                                answer: []
                            };
                            return;
                        }
                        
                        if (!currentQuestion) return;
                        
                        // 题目内容（非选项和答案的行）
                        if (!line.startsWith('#') && !line.startsWith('A.') && 
                            !line.startsWith('B.') && !line.startsWith('C.') && 
                            !line.startsWith('D.') && !line.startsWith('答案:')) {
                            currentQuestion.text = line;
                            return;
                        }
                        
                        // 选项 (A.xxx, B.xxx等)
                        const optionMatch = line.match(/^([A-Za-z])\.(.*)/);
                        if (optionMatch) {
                            currentQuestion.options.push(optionMatch[2].trim());
                            return;
                        }
                        
                        // 答案 (答案:xxx)
                        const answerMatch = line.match(/^答案:(.*)/);
                        if (answerMatch) {
                            const answerText = answerMatch[1].trim();
                            
                            if (currentQuestion.type === 'boolean') {
                                currentQuestion.answer = answerText.includes('正确') ? ['A'] : ['B'];
                            } else {
                                currentQuestion.answer = answerText.split('').map(a => a.trim().toUpperCase());
                            }
                            return;
                        }
                    });
                    
                    // 添加最后一个题目
                    if (currentQuestion) {
                        questions.push(currentQuestion);
                    }
                    
                    if (questions.length > 0) {
                        const existingQuestions = this.getQuestionBank();
                        this.saveQuestionBank([...existingQuestions, ...questions]);
                        return true;
                    }
                } catch (error) {
                    console.error('导入题库失败:', error);
                }
                
                return false;
            },
            
            // 下载文本文件
            downloadTextFile(text, filename) {
                const blob = new Blob([text], { type: 'text/plain' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = filename;
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                URL.revokeObjectURL(url);
            },
            
            // 获取题目类型文本
            getQuestionTypeText(type) {
                switch (type) {
                    case 'single': return '单选题';
                    case 'multiple': return '多选题';
                    case 'boolean': return '判断题';
                    default: return '未知题型';
                }
            },
            
            // 格式化答案显示
            formatAnswer(question) {
                if (question.type === 'boolean') {
                    return question.answer[0] === 'A' ? '正确' : '错误';
                }
                
                return question.answer.join('');
            },
            
            // 更新数据概览
            updateDashboard() {
                const questions = this.getQuestionBank();
                const singleChoice = questions.filter(q => q.type === 'single').length;
                const multipleChoice = questions.filter(q => q.type === 'multiple').length;
                const trueFalse = questions.filter(q => q.type === 'boolean').length;
                
                document.getElementById('total-questions').textContent = questions.length;
                document.getElementById('single-choice').textContent = singleChoice;
                document.getElementById('multiple-choice').textContent = multipleChoice;
                document.getElementById('true-false').textContent = trueFalse;
                
                // 更新最近测试记录
                const testRecords = this.getTestRecords();
                const recentTestsContainer = document.getElementById('recent-tests');
                
                if (testRecords.length === 0) {
                    recentTestsContainer.innerHTML = '<p class="text-gray-500 text-center py-3">暂无测试记录</p>';
                    return;
                }
                
                let html = '';
                const recentRecords = testRecords.slice(0, 5); // 显示最近5条记录
                
                recentRecords.forEach(record => {
                    html += `
                        <div class="flex justify-between items-center p-2 border-b border-gray-100">
                            <div>
                                <p class="font-medium text-sm">${record.type === 'all' ? '全部题型' : 
                                      record.type === 'single' ? '单选题' : 
                                      record.type === 'multiple' ? '多选题' : '判断题'}测试</p>
                                <p class="text-xs text-gray-500">${record.date}</p>
                            </div>
                            <div class="text-right">
                                <p class="font-bold text-primary">${record.score}/${record.total}</p>
                                <p class="text-xs text-gray-500">正确率: ${Math.round((record.score / record.total) * 100)}%</p>
                            </div>
                        </div>
                    `;
                });
                
                recentTestsContainer.innerHTML = html;
            },
            
            // 更新题库列表
            updateQuestionBankList() {
                const questions = this.getQuestionBank();
                const questionsList = document.getElementById('questions-list');
                const searchTerm = document.getElementById('search-questions').value.toLowerCase();
                const filterType = document.getElementById('filter-question-type').value;
                
                // 过滤题目
                let filteredQuestions = questions;
                if (searchTerm) {
                    filteredQuestions = filteredQuestions.filter(q => 
                        q.text.toLowerCase().includes(searchTerm) || 
                        q.options.some(o => o.toLowerCase().includes(searchTerm))
                    );
                }
                
                if (filterType !== 'all') {
                    filteredQuestions = filteredQuestions.filter(q => q.type === filterType);
                }
                
                if (filteredQuestions.length === 0) {
                    questionsList.innerHTML = '<p class="text-gray-500 text-center py-6">没有找到匹配的题目</p>';
                    return;
                }
                
                let html = '';
                filteredQuestions.forEach((question, index) => {
                    html += `
                        <div class="bg-white rounded-xl p-3 card-shadow transition-all duration-300 hover:translate-y-[-2px]">
                            <div class="flex justify-between items-start mb-2">
                                <div class="flex items-center gap-2">
                                    <span class="badge badge-primary">${this.getQuestionTypeText(question.type)}</span>
                                    <span class="text-xs text-gray-500">题目 ${index + 1}</span>
                                </div>
                                <div class="flex gap-1">
                                    <button class="text-primary hover:text-secondary edit-question-btn p-1.5 rounded-full hover:bg-primary/10 transition-colors" data-id="${question.id}" title="编辑题目">
                                        <i class="fa fa-pencil"></i>
                                    </button>
                                    <button class="text-red-500 hover:text-red-600 delete-question-btn p-1.5 rounded-full hover:bg-red-500/10 transition-colors" data-id="${question.id}" title="删除题目">
                                        <i class="fa fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            <p class="text-gray-800 text-sm mb-2">${question.text}</p>
                            <div class="space-y-1.5 mb-2">
                    `;
                    
                    if (question.type !== 'boolean') {
                        question.options.forEach((option, i) => {
                            const optionLetter = String.fromCharCode(65 + i);
                            const isCorrect = question.answer.includes(optionLetter);
                            
                            html += `
                                <div class="flex items-center gap-1.5 p-1.5 rounded-lg ${isCorrect ? 'bg-green-50 border border-green-200' : 'bg-gray-50 border border-gray-200'}">
                                    <span class="w-5 h-5 rounded-full ${isCorrect ? 'bg-green-500' : 'bg-gray-300'} flex items-center justify-center text-white text-xs">${optionLetter}</span>
                                    <span class="text-sm">${option}</span>
                                    ${isCorrect ? '<span class="ml-auto text-green-500"><i class="fa fa-check"></i></span>' : ''}
                                </div>
                            `;
                        });
                    } else {
                        const isCorrect = question.answer[0] === 'A';
                        html += `
                            <div class="flex gap-2">
                                <div class="flex-1 flex items-center gap-1.5 p-1.5 rounded-lg ${isCorrect ? 'bg-green-50 border border-green-200' : 'bg-gray-50 border border-gray-200'}">
                                    <input type="radio" name="boolean-preview-${question.id}" value="true" ${isCorrect ? 'checked' : ''} disabled>
                                    <span class="text-sm">正确</span>
                                    ${isCorrect ? '<span class="ml-auto text-green-500"><i class="fa fa-check"></i></span>' : ''}
                                </div>
                                <div class="flex-1 flex items-center gap-1.5 p-1.5 rounded-lg ${!isCorrect ? 'bg-green-50 border border-green-200' : 'bg-gray-50 border border-gray-200'}">
                                    <input type="radio" name="boolean-preview-${question.id}" value="false" ${!isCorrect ? 'checked' : ''} disabled>
                                    <span class="text-sm">错误</span>
                                    ${!isCorrect ? '<span class="ml-auto text-green-500"><i class="fa fa-check"></i></span>' : ''}
                                </div>
                            </div>
                        `;
                    }
                    
                    html += `
                            </div>
                        </div>
                    `;
                });
                
                questionsList.innerHTML = html;
                
                // 添加编辑和删除事件监听
                document.querySelectorAll('.edit-question-btn').forEach(btn => {
                    btn.addEventListener('click', () => {
                        const id = btn.getAttribute('data-id');
                        openEditModal(id);
                    });
                });
                
                document.querySelectorAll('.delete-question-btn').forEach(btn => {
                    btn.addEventListener('click', () => {
                        const id = btn.getAttribute('data-id');
                        if (confirm('确定要删除这道题目吗？')) {
                            DataStore.deleteQuestion(id);
                        }
                    });
                });
            },
            
            // 更新错题列表
            updateWrongQuestionsList() {
                const wrongQuestions = this.getWrongQuestions();
                const wrongQuestionsList = document.getElementById('wrong-questions-list');
                
                if (wrongQuestions.length === 0) {
                    wrongQuestionsList.innerHTML = '<p class="text-gray-500 text-center py-6">暂无错题记录</p>';
                    return;
                }
                
                let html = '';
                wrongQuestions.forEach((question, index) => {
                    html += `
                        <div class="bg-white rounded-xl p-3 card-shadow">
                            <div class="flex justify-between items-start mb-2">
                                <div class="flex items-center gap-2">
                                    <span class="badge badge-error">错题 ${index + 1}</span>
                                    <span class="badge badge-warning">错误次数: ${question.wrongCount || 1}</span>
                                </div>
                                <div class="flex gap-1">
                                    <button class="text-primary hover:text-secondary edit-question-btn p-1.5" data-id="${question.id}">
                                        <i class="fa fa-pencil"></i>
                                    </button>
                                    <button class="text-green-500 hover:text-green-600 remove-wrong-btn p-1.5" data-id="${question.id}">
                                        <i class="fa fa-check-circle"></i>
                                    </button>
                                </div>
                            </div>
                            <p class="text-gray-800 text-sm mb-2">${question.text}</p>
                            <div class="space-y-1.5 mb-2">
                    `;
                    
                    if (question.type !== 'boolean') {
                        question.options.forEach((option, i) => {
                            const optionLetter = String.fromCharCode(65 + i);
                            const isCorrect = question.answer.includes(optionLetter);
                            
                            html += `
                                <div class="flex items-center gap-1.5 p-1.5 rounded-lg ${isCorrect ? 'bg-green-50 border border-green-200' : 'bg-gray-50 border border-gray-200'}">
                                    <span class="w-5 h-5 rounded-full ${isCorrect ? 'bg-green-500' : 'bg-gray-300'} flex items-center justify-center text-white text-xs">${optionLetter}</span>
                                    <span class="text-sm">${option}</span>
                                    ${isCorrect ? '<span class="ml-auto text-green-500"><i class="fa fa-check"></i></span>' : ''}
                                </div>
                            `;
                        });
                    } else {
                        const isCorrect = question.answer[0] === 'A';
                        html += `
                            <div class="flex gap-2">
                                <div class="flex-1 flex items-center gap-1.5 p-1.5 rounded-lg ${isCorrect ? 'bg-green-50 border border-green-200' : 'bg-gray-50 border border-gray-200'}">
                                    <input type="radio" name="boolean-wrong-${question.id}" value="true" ${isCorrect ? 'checked' : ''} disabled>
                                    <span class="text-sm">正确</span>
                                    ${isCorrect ? '<span class="ml-auto text-green-500"><i class="fa fa-check"></i></span>' : ''}
                                </div>
                                <div class="flex-1 flex items-center gap-1.5 p-1.5 rounded-lg ${!isCorrect ? 'bg-green-50 border border-green-200' : 'bg-gray-50 border border-gray-200'}">
                                    <input type="radio" name="boolean-wrong-${question.id}" value="false" ${!isCorrect ? 'checked' : ''} disabled>
                                    <span class="text-sm">错误</span>
                                    ${!isCorrect ? '<span class="ml-auto text-green-500"><i class="fa fa-check"></i></span>' : ''}
                                </div>
                            </div>
                        `;
                    }
                    
                    html += `
                            </div>
                        </div>
                    `;
                });
                
                wrongQuestionsList.innerHTML = html;
                
                // 添加编辑和移除错题事件监听
                document.querySelectorAll('.edit-question-btn').forEach(btn => {
                    btn.addEventListener('click', () => {
                        const id = btn.getAttribute('data-id');
                        openEditModal(id);
                    });
                });
                
                document.querySelectorAll('.remove-wrong-btn').forEach(btn => {
                    btn.addEventListener('click', () => {
                        const id = btn.getAttribute('data-id');
                        DataStore.removeWrongQuestion(id);
                    });
                });
            }
        };

        // 测试模块 - 重点优化多选题答题体验
        const QuizManager = {
            currentQuiz: null,
            
            // 开始新测试
            startQuiz(type, count, isWrongQuiz = false) {
                // 清除之前的测试
                DataStore.clearCurrentQuiz();
                
                let questions = isWrongQuiz ? DataStore.getWrongQuestions() : DataStore.getQuestionBank();
                
                // 过滤题目类型
                if (type !== 'all') {
                    questions = questions.filter(q => q.type === type);
                }
                
                // 检查题目数量
                if (questions.length === 0) {
                    alert('没有找到符合条件的题目');
                    return;
                }
                
                // 限制题目数量
                const maxQuestions = Math.min(count, questions.length);
                
                // 随机选择题目
                const shuffledQuestions = [...questions].sort(() => 0.5 - Math.random());
                const selectedQuestions = shuffledQuestions.slice(0, maxQuestions);
                
                // 创建测试对象
                this.currentQuiz = {
                    type,
                    questions: selectedQuestions.map(q => ({
                        id: q.id,
                        question: q,
                        userAnswer: null,
                        isCorrect: null
                    })),
                    currentQuestionIndex: 0,
                    score: 0
                };
                
                // 保存当前测试
                DataStore.saveCurrentQuiz(this.currentQuiz);
                
                // 显示测试界面
                document.getElementById('quiz-settings').classList.add('hidden');
                document.getElementById('quiz-container').classList.remove('hidden');
                document.getElementById('quiz-result').classList.add('hidden');
                
                // 更新题目
                this.updateQuestion();
            },
            
            // 继续之前的测试
            continueQuiz() {
                this.currentQuiz = DataStore.getCurrentQuiz();
                
                if (!this.currentQuiz) {
                    alert('没有找到未完成的测试');
                    return false;
                }
                
                // 显示测试界面
                document.getElementById('quiz-settings').classList.add('hidden');
                document.getElementById('quiz-container').classList.remove('hidden');
                document.getElementById('quiz-result').classList.add('hidden');
                
                // 更新题目
                this.updateQuestion();
                
                return true;
            },
            
            // 更新当前题目
            updateQuestion() {
                if (!this.currentQuiz) return;
                
                const currentQuestion = this.currentQuiz.questions[this.currentQuiz.currentQuestionIndex];
                const question = currentQuestion.question;
                
                // 隐藏答案反馈
                const feedbackElement = document.getElementById('answer-feedback');
                feedbackElement.classList.add('hidden');
                
                // 隐藏正确答案提示
                const correctAnswerHint = document.getElementById('correct-answer-hint');
                correctAnswerHint.classList.add('hidden');
                
                // 隐藏提交提示
                const submitPromptContainer = document.getElementById('submit-prompt-container');
                submitPromptContainer.classList.add('hidden');
                
                // 更新题型标签
                const typeTag = document.getElementById('question-type-tag');
                const typeMap = {
                    'single': { text: '单选题', class: 'type-single' },
                    'multiple': { text: '多选题', class: 'type-multiple' },
                    'boolean': { text: '判断题', class: 'type-boolean' }
                };
                typeTag.textContent = typeMap[question.type].text;
                typeTag.className = `question-type-tag ${typeMap[question.type].class}`;
                
                // 更新题目文本
                document.getElementById('quiz-question-text').textContent = question.text;
                
                // 更新题目数量
                document.getElementById('current-question-number').textContent = 
                    `${this.currentQuiz.currentQuestionIndex + 1}/${this.currentQuiz.questions.length}`;
                
                // 更新得分
                document.getElementById('current-score').textContent = this.currentQuiz.score;
                
                // 更新按钮状态
                document.getElementById('prev-question-btn').disabled = this.currentQuiz.currentQuestionIndex === 0;
                document.getElementById('next-question-btn').textContent = 
                    this.currentQuiz.currentQuestionIndex === this.currentQuiz.questions.length - 1 ? '完成' : '下一题';
                
                // 生成选项
                const optionsContainer = document.getElementById('quiz-options');
                optionsContainer.innerHTML = '';
                
                if (question.type === 'boolean') {
                    // 判断题
                    optionsContainer.innerHTML = `
                        <div class="flex gap-3">
                            <div class="flex-1">
                                <label class="option-item ${currentQuestion.userAnswer === 'A' ? 'selected' : ''} ${currentQuestion.isCorrect !== null ? (currentQuestion.userAnswer === 'A' && currentQuestion.isCorrect ? 'correct' : (currentQuestion.userAnswer === 'A' && !currentQuestion.isCorrect ? 'incorrect' : '')) : ''}">
                                    <div class="option-marker">A</div>
                                    <span>正确</span>
                                    <input type="radio" name="quiz-boolean-answer" value="A" class="hidden" ${currentQuestion.userAnswer === 'A' ? 'checked' : ''} ${currentQuestion.isCorrect !== null ? 'disabled' : ''}>
                                </label>
                            </div>
                            <div class="flex-1">
                                <label class="option-item ${currentQuestion.userAnswer === 'B' ? 'selected' : ''} ${currentQuestion.isCorrect !== null ? (currentQuestion.userAnswer === 'B' && currentQuestion.isCorrect ? 'correct' : (currentQuestion.userAnswer === 'B' && !currentQuestion.isCorrect ? 'incorrect' : '')) : ''}">
                                    <div class="option-marker">B</div>
                                    <span>错误</span>
                                    <input type="radio" name="quiz-boolean-answer" value="B" class="hidden" ${currentQuestion.userAnswer === 'B' ? 'checked' : ''} ${currentQuestion.isCorrect !== null ? 'disabled' : ''}>
                                </label>
                            </div>
                        </div>
                    `;
                    
                    // 添加事件监听
                    document.querySelectorAll('input[name="quiz-boolean-answer"]').forEach(radio => {
                        const label = radio.closest('.option-item');
                        label.addEventListener('click', () => {
                            if (currentQuestion.isCorrect === null) {
                                radio.checked = true;
                                this.selectAnswer(radio.value);
                            }
                        });
                    });
                } else {
                    // 单选题或多选题
                    question.options.forEach((option, index) => {
                        const optionLetter = String.fromCharCode(65 + index);
                        const isSelected = currentQuestion.userAnswer && 
                            (question.type === 'single' ? 
                                currentQuestion.userAnswer === optionLetter : 
                                currentQuestion.userAnswer.includes(optionLetter));
                        
                        // 判断是否应该显示正确/错误样式
                        let statusClass = '';
                        if (currentQuestion.isCorrect !== null) {
                            const isCorrectAnswer = question.answer.includes(optionLetter);
                            if (isSelected) {
                                statusClass = currentQuestion.isCorrect ? 'correct' : 'incorrect';
                            } else if (isCorrectAnswer) {
                                statusClass = 'correct';
                            }
                        }
                        
                        const inputType = question.type === 'single' ? 'radio' : 'checkbox';
                        const name = question.type === 'single' ? 'quiz-single-answer' : `quiz-multiple-answer`;
                        
                        const optionElement = document.createElement('label');
                        optionElement.className = `option-item ${isSelected ? 'selected' : ''} ${statusClass}`;
                        optionElement.innerHTML = `
                            <div class="option-marker">${optionLetter}</div>
                            <span>${option}</span>
                            <input type="${inputType}" 
                                   name="${name}" 
                                   value="${optionLetter}" 
                                   class="hidden"
                                   ${isSelected ? 'checked' : ''}
                                   ${currentQuestion.isCorrect !== null ? 'disabled' : ''}>
                        `;
                        
                        optionsContainer.appendChild(optionElement);
                        
                        // 添加事件监听
                        optionElement.addEventListener('click', () => {
                            if (currentQuestion.isCorrect === null) {
                                const input = optionElement.querySelector('input');
                                if (inputType === 'checkbox') {
                                    input.checked = !input.checked;
                                } else {
                                    // 单选按钮需要取消其他选项
                                    document.querySelectorAll(`input[name="${name}"]`).forEach(inp => {
                                        inp.checked = false;
                                        inp.closest('.option-item').classList.remove('selected');
                                    });
                                    input.checked = true;
                                }
                                
                                // 对于多选题，收集所有选中的选项并显示提交提示
                                if (question.type === 'multiple') {
                                    const allChecked = Array.from(document.querySelectorAll(`input[name="${name}"]:checked`))
                                        .map(inp => inp.value);
                                    
                                    // 更新选中状态
                                    document.querySelectorAll('.option-item').forEach(item => {
                                        const inp = item.querySelector('input');
                                        if (inp.checked) {
                                            item.classList.add('selected');
                                        } else {
                                            item.classList.remove('selected');
                                        }
                                    });
                                    
                                    // 显示或隐藏提交提示（仅多选题）
                                    const submitPromptContainer = document.getElementById('submit-prompt-container');
                                    if (allChecked.length > 0) {
                                        submitPromptContainer.classList.remove('hidden');
                                        // 保存当前选择但不判断
                                        currentQuestion.userAnswer = allChecked;
                                        DataStore.saveCurrentQuiz(this.currentQuiz);
                                    } else {
                                        submitPromptContainer.classList.add('hidden');
                                    }
                                } else {
                                    // 单选题直接判断
                                    this.selectAnswer(optionLetter);
                                }
                            }
                        });
                    });
                }
                
                // 如果已经提交答案，显示正确答案
                if (currentQuestion.isCorrect !== null) {
                    this.showCorrectAnswer(question);
                }
                
                // 为多选题添加提交事件
                document.getElementById('submit-btn').addEventListener('click', () => {
                    if (question.type === 'multiple' && currentQuestion.isCorrect === null) {
                        this.checkAnswer();
                        this.showAnswerFeedback(currentQuestion.isCorrect);
                        this.showCorrectAnswer(question);
                        submitPromptContainer.classList.add('hidden');
                        DataStore.saveCurrentQuiz(this.currentQuiz);
                        this.updateQuestion();
                    }
                });
            },
            
            // 选择单选题/判断题答案
            selectAnswer(answer) {
                if (!this.currentQuiz) return;
                
                const currentQuestion = this.currentQuiz.questions[this.currentQuiz.currentQuestionIndex];
                const question = currentQuestion.question;
                
                // 如果已经判断过，不再重复处理
                if (currentQuestion.isCorrect !== null) return;
                
                // 单选题或判断题
                currentQuestion.userAnswer = answer;
                
                // 检查答案是否正确
                this.checkAnswer();
                
                // 显示答案提示
                this.showAnswerFeedback(currentQuestion.isCorrect);
                
                // 显示正确答案
                this.showCorrectAnswer(question);
                
                // 保存当前测试
                DataStore.saveCurrentQuiz(this.currentQuiz);
                
                // 更新界面显示结果
                this.updateQuestion();
            },
            
            // 显示答案反馈
            showAnswerFeedback(isCorrect) {
                const feedbackElement = document.getElementById('answer-feedback');
                feedbackElement.className = `answer-feedback ${isCorrect ? 'feedback-correct' : 'feedback-incorrect'}`;
                feedbackElement.textContent = isCorrect ? '回答正确！' : '回答错误！';
                feedbackElement.classList.remove('hidden');
            },
            
            // 显示正确答案
            showCorrectAnswer(question) {
                const correctAnswerHint = document.getElementById('correct-answer-hint');
                
                let answerText = '';
                if (question.type === 'boolean') {
                    answerText = question.answer[0] === 'A' ? '正确' : '错误';
                } else {
                    answerText = question.answer.map(letter => {
                        const index = letter.charCodeAt(0) - 65;
                        return `${letter}.${question.options[index]}`;
                    }).join('，');
                }
                
                correctAnswerHint.innerHTML = `<strong>正确答案：</strong>${answerText}`;
                correctAnswerHint.classList.remove('hidden');
            },
            
            // 检查答案
            checkAnswer() {
                if (!this.currentQuiz) return;
                
                const currentQuestion = this.currentQuiz.questions[this.currentQuiz.currentQuestionIndex];
                const question = currentQuestion.question;
                
                if (!currentQuestion.userAnswer) {
                    currentQuestion.isCorrect = null;
                    return;
                }
                
                let isCorrect = false;
                
                if (question.type === 'single' || question.type === 'boolean') {
                    // 单选题或判断题
                    isCorrect = currentQuestion.userAnswer === question.answer[0];
                } else {
                    // 多选题
                    if (currentQuestion.userAnswer.length !== question.answer.length) {
                        isCorrect = false;
                    } else {
                        // 检查所有选项是否匹配
                        isCorrect = question.answer.every(a => currentQuestion.userAnswer.includes(a));
                    }
                }
                
                currentQuestion.isCorrect = isCorrect;
                
                // 更新得分
                if (isCorrect) {
                    this.currentQuiz.score++;
                } else {
                    // 添加到错题记录
                    DataStore.addWrongQuestion(question);
                }
                
                // 保存当前测试
                DataStore.saveCurrentQuiz(this.currentQuiz);
            },
            
            // 下一题
            nextQuestion() {
                if (!this.currentQuiz) return;
                
                // 如果是最后一题，显示结果
                if (this.currentQuiz.currentQuestionIndex === this.currentQuiz.questions.length - 1) {
                    this.showResult();
                    return;
                }
                
                // 否则前进到下一题
                this.currentQuiz.currentQuestionIndex++;
                this.updateQuestion();
                
                // 保存当前测试
                DataStore.saveCurrentQuiz(this.currentQuiz);
            },
            
            // 上一题
            prevQuestion() {
                if (!this.currentQuiz || this.currentQuiz.currentQuestionIndex === 0) return;
                
                this.currentQuiz.currentQuestionIndex--;
                this.updateQuestion();
            },
            
            // 显示测试结果
            showResult() {
                if (!this.currentQuiz) return;
                
                // 计算正确和错误的题目数量
                const correctCount = this.currentQuiz.score;
                const incorrectCount = this.currentQuiz.questions.length - correctCount;
                
                // 更新结果界面
                document.getElementById('final-score').textContent = correctCount;
                document.getElementById('total-quiz-questions').textContent = this.currentQuiz.questions.length;
                document.getElementById('result-total').textContent = this.currentQuiz.questions.length;
                document.getElementById('result-correct').textContent = correctCount;
                document.getElementById('result-incorrect').textContent = incorrectCount;
                
                // 显示结果界面
                document.getElementById('quiz-container').classList.add('hidden');
                document.getElementById('quiz-result').classList.remove('hidden');
                
                // 添加测试记录
                DataStore.addTestRecord({
                    type: this.currentQuiz.type,
                    total: this.currentQuiz.questions.length,
                    score: correctCount
                });
                
                // 清除当前测试
                DataStore.clearCurrentQuiz();
                this.currentQuiz = null;
            },
            
            // 中途结束测试
            endQuiz() {
                if (!this.currentQuiz) return;
                
                if (confirm('确定要中途结束测试吗？')) {
                    // 计算已完成的题目
                    const completedQuestions = this.currentQuiz.questions.filter(q => q.isCorrect !== null).length;
                    
                    // 添加测试记录
                    DataStore.addTestRecord({
                        type: this.currentQuiz.type,
                        total: completedQuestions,
                        score: this.currentQuiz.score
                    });
                    
                    // 清除当前测试
                    DataStore.clearCurrentQuiz();
                    this.currentQuiz = null;
                    
                    // 返回测试设置界面
                    document.getElementById('quiz-container').classList.add('hidden');
                    document.getElementById('quiz-settings').classList.remove('hidden');
                }
            }
        };

        // 初始化应用
        function initApp() {
            // 初始化数据存储
            DataStore.init();
            
            // 更新界面
            DataStore.updateDashboard();
            DataStore.updateQuestionBankList();
            DataStore.updateWrongQuestionsList();
            
            // 设置导航切换
            setupNavigation();
            
            // 设置编辑题目模态框
            setupEditModal();
            
            // 设置测试功能
            setupQuizFunctionality();
            
            // 设置题库导入导出
            setupImportExport();
            
            // 检查是否有未完成的测试
            checkForUnfinishedQuiz();
        }

        // 设置导航切换
        function setupNavigation() {
            const navItems = document.querySelectorAll('.nav-item');
            const sections = document.querySelectorAll('.section-content');
            
            navItems.forEach(item => {
                item.addEventListener('click', (e) => {
                    e.preventDefault();
                    
                    // 更新导航项状态
                    navItems.forEach(nav => nav.classList.remove('active'));
                    item.classList.add('active');
                    
                    // 显示对应的内容区域
                    const targetSection = item.getAttribute('data-section');
                    sections.forEach(section => {
                        section.classList.add('hidden');
                    });
                    document.getElementById(`${targetSection}-section`).classList.remove('hidden');
                });
            });
        }

        // 设置编辑题目模态框
        function setupEditModal() {
            const editModal = document.getElementById('edit-modal');
            const closeEditModal = document.getElementById('close-edit-modal');
            const cancelEditQuestion = document.getElementById('cancel-edit-question');
            const editQuestionForm = document.getElementById('edit-question-form');
            const editQuestionType = document.getElementById('edit-question-type');
            const editOptionsContainer = document.getElementById('edit-options-container');
            const editBooleanOptions = document.getElementById('edit-boolean-options');
            const editAnswerSelection = document.getElementById('edit-answer-selection');
            const editAddOptionBtn = document.getElementById('edit-add-option-btn');
            
            // 添加选项按钮
            editAddOptionBtn.addEventListener('click', () => {
                const optionsList = document.querySelector('.edit-options-list');
                const currentCount = optionsList.children.length;
                
                // 限制最大选项数量
                const maxOptions = editQuestionType.value === 'single' ? 6 : 10;
                if (currentCount >= maxOptions) {
                    alert(`最多只能添加${maxOptions}个选项`);
                    return;
                }
                
                const optionLetter = String.fromCharCode(65 + currentCount);
                
                const optionDiv = document.createElement('div');
                optionDiv.className = 'flex items-center gap-2';
                optionDiv.innerHTML = `
                    <div class="w-7 h-7 rounded-full bg-primary flex items-center justify-center text-white font-medium">${optionLetter}</div>
                    <input type="text" class="edit-option-input input-field" placeholder="选项${optionLetter}">
                    <button type="button" class="edit-remove-option-btn text-gray-400 hover:text-red-500">
                        <i class="fa fa-times"></i>
                    </button>
                `;
                
                optionsList.appendChild(optionDiv);
                
                // 更新删除按钮可见性
                updateEditRemoveButtonsVisibility();
                
                // 更新答案选择
                updateEditAnswerSelection();
            });
            
            // 为编辑模态框的删除按钮添加事件
            document.addEventListener('click', (e) => {
                if (e.target.closest('.edit-remove-option-btn')) {
                    const btn = e.target.closest('.edit-remove-option-btn');
                    const optionCount = document.querySelectorAll('.edit-options-list > div').length;
                    
                    // 确保至少保留2个选项
                    if (optionCount > 2) {
                        btn.closest('.flex').remove();
                        updateEditOptionLabels();
                        updateEditAnswerSelection();
                        updateEditRemoveButtonsVisibility();
                    } else {
                        alert('至少需要保留2个选项');
                    }
                }
            });
            
            // 为编辑模态框的判断题选项添加点击事件
            document.addEventListener('click', (e) => {
                if (e.target.closest('#edit-boolean-options .option-item')) {
                    const item = e.target.closest('.option-item');
                    const input = item.querySelector('input');
                    document.querySelectorAll('#edit-boolean-options input').forEach(inp => {
                        inp.checked = false;
                        inp.closest('.option-item').classList.remove('selected');
                    });
                    input.checked = true;
                    item.classList.add('selected');
                }
            });
            
            // 题目类型切换
            editQuestionType.addEventListener('change', () => {
                if (editQuestionType.value === 'boolean') {
                    editOptionsContainer.classList.add('hidden');
                    editBooleanOptions.classList.remove('hidden');
                    editAnswerSelection.classList.add('hidden');
                } else {
                    editOptionsContainer.classList.remove('hidden');
                    editBooleanOptions.classList.add('hidden');
                    editAnswerSelection.classList.remove('hidden');
                    
                    // 根据题型调整选项数量和答案选择类型
                    if (editQuestionType.value === 'single') {
                        // 单选题最多6个选项
                        const currentOptions = document.querySelectorAll('.edit-options-list > div').length;
                        if (currentOptions > 6) {
                            while (document.querySelectorAll('.edit-options-list > div').length > 6) {
                                document.querySelector('.edit-options-list > div:last-child').remove();
                            }
                        }
                    }
                    
                    updateEditAnswerSelection();
                }
                
                // 显示删除按钮（如果有多个选项）
                updateEditRemoveButtonsVisibility();
            });
            
            // 更新编辑模态框的选项标签（A, B, C...）
            function updateEditOptionLabels() {
                const options = document.querySelectorAll('.edit-options-list > div');
                options.forEach((option, index) => {
                    const letter = String.fromCharCode(65 + index);
                    option.querySelector('.rounded-full').textContent = letter;
                    option.querySelector('.edit-option-input').placeholder = `选项${letter}`;
                });
            }
            
            // 更新编辑模态框的删除按钮可见性
            function updateEditRemoveButtonsVisibility() {
                const options = document.querySelectorAll('.edit-options-list > div');
                const removeButtons = document.querySelectorAll('.edit-remove-option-btn');
                
                if (options.length > 2) {
                    removeButtons.forEach(btn => btn.classList.remove('hidden'));
                } else {
                    removeButtons.forEach(btn => btn.classList.add('hidden'));
                }
            }
            
            // 更新编辑模态框的答案选择区域
            function updateEditAnswerSelection() {
                const questionType = editQuestionType.value;
                if (questionType === 'boolean') return;
                
                const optionsCount = document.querySelectorAll('.edit-options-list > div').length;
                editAnswerSelection.innerHTML = '';
                
                for (let i = 0; i < optionsCount; i++) {
                    const optionLetter = String.fromCharCode(65 + i);
                    const inputType = questionType === 'single' ? 'radio' : 'checkbox';
                    
                    const label = document.createElement('label');
                    label.className = 'flex items-center gap-1 p-2 border rounded';
                    label.innerHTML = `
                        <input type="${inputType}" name="edit-answer-option" value="${optionLetter}" class="mr-1">
                        <span>${optionLetter}</span>
                    `;
                    
                    editAnswerSelection.appendChild(label);
                }
            }
            
            // 关闭模态框
            closeEditModal.addEventListener('click', () => {
                editModal.classList.add('hidden');
            });
            
            cancelEditQuestion.addEventListener('click', () => {
                editModal.classList.add('hidden');
            });
            
            // 表单提交
            editQuestionForm.addEventListener('submit', (e) => {
                e.preventDefault();
                
                const id = document.getElementById('edit-question-id').value;
                const type = editQuestionType.value;
                const text = document.getElementById('edit-question-text').value.trim();
                
                // 验证题目内容
                if (!text) {
                    alert('请输入题目内容');
                    return;
                }
                
                let options = [];
                let answer = [];
                
                if (type === 'boolean') {
                    // 判断题
                    const selectedAnswer = document.querySelector('input[name="edit-boolean-answer"]:checked');
                    if (!selectedAnswer) {
                        alert('请选择正确答案');
                        return;
                    }
                    
                    answer = [selectedAnswer.value === 'true' ? 'A' : 'B'];
                } else {
                    // 单选题或多选题
                    const optionInputs = document.querySelectorAll('.edit-option-input');
                    
                    // 收集选项
                    optionInputs.forEach(input => {
                        const optionText = input.value.trim();
                        if (optionText) {
                            options.push(optionText);
                        } else {
                            alert('选项内容不能为空');
                            return;
                        }
                    });
                    
                    // 验证选项
                    if (options.length < 2) {
                        alert('请至少输入2个选项');
                        return;
                    }
                    
                    // 收集答案
                    const selectedAnswers = document.querySelectorAll('input[name="edit-answer-option"]:checked');
                    if (selectedAnswers.length === 0) {
                        alert('请选择正确答案');
                        return;
                    }
                    
                    selectedAnswers.forEach(input => {
                        answer.push(input.value);
                    });
                }
                
                // 创建更新后的题目对象
                const updatedQuestion = {
                    id,
                    type,
                    text,
                    options,
                    answer
                };
                
                // 更新题目
                if (DataStore.updateQuestion(updatedQuestion)) {
                    // 关闭模态框
                    editModal.classList.add('hidden');
                    
                    // 显示成功消息
                    alert('题目更新成功');
                } else {
                    alert('更新题目失败');
                }
            });
        }

        // 打开编辑模态框
        function openEditModal(id) {
            const questions = DataStore.getQuestionBank();
            const question = questions.find(q => q.id === id);
            
            if (!question) {
                alert('未找到题目');
                return;
            }
            
            // 填充表单数据
            document.getElementById('edit-question-id').value = question.id;
            document.getElementById('edit-question-type').value = question.type;
            document.getElementById('edit-question-text').value = question.text;
            
            const editOptionsContainer = document.getElementById('edit-options-container');
            const editBooleanOptions = document.getElementById('edit-boolean-options');
            const editAnswerSelection = document.getElementById('edit-answer-selection');
            const editOptionsList = document.querySelector('.edit-options-list');
            
            // 清空现有选项
            editOptionsList.innerHTML = '';
            
            if (question.type === 'boolean') {
                // 判断题
                editOptionsContainer.classList.add('hidden');
                editBooleanOptions.classList.remove('hidden');
                editAnswerSelection.classList.add('hidden');
                
                // 选中正确答案
                const isTrueAnswer = question.answer[0] === 'A';
                document.querySelector(`input[name="edit-boolean-answer"][value="${isTrueAnswer}"]`).checked = true;
                // 更新选中样式
                document.querySelectorAll('#edit-boolean-options .option-item').forEach(item => {
                    item.classList.remove('selected');
                });
                document.querySelector(`input[name="edit-boolean-answer"][value="${isTrueAnswer}"]`).closest('.option-item').classList.add('selected');
            } else {
                // 单选题或多选题
                editOptionsContainer.classList.remove('hidden');
                editBooleanOptions.classList.add('hidden');
                editAnswerSelection.classList.remove('hidden');
                
                // 添加选项
                question.options.forEach((option, index) => {
                    const optionLetter = String.fromCharCode(65 + index);
                    
                    const optionDiv = document.createElement('div');
                    optionDiv.className = 'flex items-center gap-2';
                    optionDiv.innerHTML = `
                        <div class="w-7 h-7 rounded-full bg-primary flex items-center justify-center text-white font-medium">${optionLetter}</div>
                        <input type="text" class="edit-option-input input-field" placeholder="选项${optionLetter}" value="${option}">
                        <button type="button" class="edit-remove-option-btn text-gray-400 hover:text-red-500 ${question.options.length > 2 ? '' : 'hidden'}">
                            <i class="fa fa-times"></i>
                        </button>
                    `;
                    
                    editOptionsList.appendChild(optionDiv);
                });
                
                // 更新答案选择
                updateEditAnswerSelection();
                
                // 选中正确答案
                question.answer.forEach(letter => {
                    const input = document.querySelector(`input[name="edit-answer-option"][value="${letter}"]`);
                    if (input) input.checked = true;
                });
            }
            
            // 显示模态框
            document.getElementById('edit-modal').classList.remove('hidden');
        }

        // 设置测试功能
        function setupQuizFunctionality() {
            const startQuizBtn = document.getElementById('start-quiz-btn');
            const startWrongQuizBtn = document.getElementById('start-wrong-quiz-btn');
            const nextQuestionBtn = document.getElementById('next-question-btn');
            const prevQuestionBtn = document.getElementById('prev-question-btn');
            const restartQuizBtn = document.getElementById('restart-quiz-btn');
            const endQuizBtn = document.getElementById('end-quiz-btn');
            
            // 开始测试
            startQuizBtn.addEventListener('click', () => {
                const type = document.getElementById('quiz-question-type').value;
                const count = parseInt(document.getElementById('quiz-question-count').value);
                
                if (isNaN(count) || count < 1) {
                    alert('请输入有效的题目数量');
                    return;
                }
                
                QuizManager.startQuiz(type, count);
            });
            
            // 开始错题测试
            startWrongQuizBtn.addEventListener('click', () => {
                const wrongQuestions = DataStore.getWrongQuestions();
                
                if (wrongQuestions.length === 0) {
                    alert('没有错题记录');
                    return;
                }
                
                QuizManager.startQuiz('all', wrongQuestions.length, true);
                
                // 切换到测试页面
                document.querySelector('.nav-item[data-section="start-quiz"]').click();
            });
            
            // 下一题
            nextQuestionBtn.addEventListener('click', () => {
                QuizManager.nextQuestion();
            });
            
            // 上一题
            prevQuestionBtn.addEventListener('click', () => {
                QuizManager.prevQuestion();
            });
            
            // 重新测试
            restartQuizBtn.addEventListener('click', () => {
                document.getElementById('quiz-result').classList.add('hidden');
                document.getElementById('quiz-settings').classList.remove('hidden');
            });
            
            // 中途结束测试
            endQuizBtn.addEventListener('click', () => {
                QuizManager.endQuiz();
            });
            
            // 设置搜索和过滤
            document.getElementById('search-questions').addEventListener('input', () => {
                DataStore.updateQuestionBankList();
            });
            
            document.getElementById('filter-question-type').addEventListener('change', () => {
                DataStore.updateQuestionBankList();
            });
        }

        // 设置题库导入导出
        function setupImportExport() {
            const exportBtn = document.getElementById('export-btn');
            const importFile = document.getElementById('import-file');
            const clearAllBtn = document.getElementById('clear-all-btn');
            
            // 导出题库
            exportBtn.addEventListener('click', () => {
                DataStore.exportQuestionBank();
            });
            
            // 导入题库
            importFile.addEventListener('change', (e) => {
                const file = e.target.files[0];
                
                if (!file) return;
                
                const reader = new FileReader();
                reader.onload = (event) => {
                    const text = event.target.result;
                    
                    if (DataStore.importQuestionBank(text)) {
                        alert('题库导入成功');
                    } else {
                        alert('题库导入失败，请检查文件格式是否正确\n正确格式示例：\n#1 单选题\n这是一道单选题\nA.选项一\nB.选项二\n答案:A');
                    }
                    
                    // 重置文件输入
                    importFile.value = '';
                };
                
                reader.readAsText(file);
            });
            
            // 清空题库
            clearAllBtn.addEventListener('click', () => {
                if (confirm('确定要清空整个题库吗？此操作不可撤销！')) {
                    DataStore.saveQuestionBank([]);
                    DataStore.saveWrongQuestions([]);
                    alert('题库已清空');
                }
            });
        }

        // 检查是否有未完成的测试
        function checkForUnfinishedQuiz() {
            const currentQuiz = DataStore.getCurrentQuiz();
            
            if (currentQuiz) {
                if (confirm('检测到未完成的测试，是否继续？')) {
                    // 切换到测试页面并继续
                    document.querySelector('.nav-item[data-section="start-quiz"]').click();
                    QuizManager.continueQuiz();
                }
            }
        }

        // 页面加载完成后初始化应用
        document.addEventListener('DOMContentLoaded', initApp);
    </script>
</body>
</html>